package com.fenghongzhang.module_main.ui.main.viewmodel

import MotoCircleNavigationItem
import androidx.lifecycle.viewModelScope
import com.fenghongzhang.lib_core.base.BaseViewModel
import com.fenghongzhang.lib_core.state.Default
import com.fenghongzhang.lib_core.state.RequestEvent
import com.fenghongzhang.lib_core.state.Success
import com.fenghongzhang.module_main.repository.MallRepository
import com.fenghongzhang.module_main.ui.main.repository.MainRepository
import com.jczy.cyclone.mmkv.AuthMMKV
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
    private val mRepository: MainRepository, private val mallRepository: MallRepository
) : BaseViewModel() {
    private val _navigationState = MutableStateFlow<RequestEvent>(Default)
    val navigationState
        get() = _navigationState.asStateFlow()


    val mNavigationItem = mutableListOf<MotoCircleNavigationItem>()

    fun getFixedNavigationItem() {

        val navList = listOf(
            MotoCircleNavigationEnum.HOT,
            MotoCircleNavigationEnum.TOPIC,
            MotoCircleNavigationEnum.INFORMATION,
            MotoCircleNavigationEnum.FOLLOW
        )

        execute(action = mRepository.blankApi(), onStart = {
            mNavigationItem.clear()
            navList.forEach {
                mNavigationItem.add(
                    MotoCircleNavigationItem(
                        navigationId = it.navId.toString(),
                        sort = it.sort,
                        status = 1,
                        title = it.title,
                        type = it.type,
                        value = it.name
                    )
                )
            }
            _navigationState.emit(Success)
        })


    }

}